﻿/*
 *  Copyright (c) 2012 Brandon Ellenberger
 *
 *  This file is part of OpSatPlan.
 *
 *  OpSatPlan is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  OpSatPlan is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with OpSatPlan.  If not, see <http://www.gnu.org/licenses/>.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace OpSatPlan.PlanningGraph
{
    public class RelaxedPlanningGraph
    {
        private List<Level> mLevels;
        private Domain mDomain;
        private Problem mProblem;

        public Domain Domain
        {
            get
            {
                return this.mDomain;
            }
        }
        public Problem Problem
        {
            get
            {
                return this.mProblem;
            }
        }
        public RelaxedPlanningGraph(Domain domain, Problem problem)
        {
            this.mDomain = domain;
            this.mProblem = problem;
            this.mLevels = new List<Level>();

            Level firstLevel = new Level(this);
            this.mLevels.Add(firstLevel);
        }

        public Level AddLevel()
        {
            Level newLevel;
            newLevel = new Level(this, this.GetLastLevel());
            this.mLevels.Add(newLevel);
            return newLevel;
        }

        public Level GetLastLevel()
        {
            if (this.mLevels.Count == 0)
                return null;
            return this.mLevels[this.mLevels.Count - 1];
        }

        public void RemoveLastLevel()
        {
            if (this.mLevels.Count > 0)
            {
                this.mLevels.RemoveAt(this.mLevels.Count - 1);
            }
        }

        public ReadOnlyCollection<Level> Levels
        {
            get
            {
                return new ReadOnlyCollection<Level>(this.mLevels);
            }
        }



        public int Depth
        {
            get
            {
                return this.mLevels.Count;
            }
        }

        public int TimeSteps
        {
            get { return this.mLevels.Count - 1; }
        }
    }
}
